import { FastifyInstance } from "fastify";
import { MetroStation } from "@db";
import { Static, Type } from "@sinclair/typebox";

const metroParams = Type.Object({
    cityId: Type.Number(),
});

export const metro = async (fastify: FastifyInstance) => {
    fastify.get<{
        Params: Static<typeof metroParams>;
    }>(
        "/metro/:cityId",
        {
            schema: {
                params: metroParams,
            },
        },
        async (req, res) => {
            return res.send(
                await MetroStation.findAll({
                    where: {
                        cityId: req.params.cityId,
                    },
                })
            );
        }
    );
};
